home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / oobr / br-clos.el < prev    next >
Encoding:
Text File  |  1995-08-26  |  9.1 KB  |  250 lines

  1. ;;!emacs
  2. ;;
  3. ;; FILE:         br-clos.el
  4. ;; SUMMARY:      Support routines for CLOS inheritance browsing.
  5. ;; USAGE:        GNU Emacs Lisp Library
  6. ;; KEYWORDS:     lisp, oop, tools
  7. ;;
  8. ;; AUTHOR:       Bob Weiner
  9. ;; ORG:          Motorola Inc.
  10. ;;
  11. ;; ORIG-DATE:    29-Jul-90
  12. ;; LAST-MOD:     23-Aug-95 at 14:01:24 by Bob Weiner
  13. ;;
  14. ;; Copyright (C) 1990-1995  Free Software Foundation, Inc.
  15. ;; See the file BR-COPY for license information.
  16. ;;
  17. ;; This file is part of the OO-Browser.
  18. ;;
  19. ;; DESCRIPTION:  
  20. ;;
  21. ;;   Properly supports CLOS multiple inheritance.
  22. ;;
  23. ;;   See 'clos-class-def-regexp' for regular expression that matches class
  24. ;;   definitions.
  25. ;;
  26. ;; DESCRIP-END.
  27.  
  28. ;;; ************************************************************************
  29. ;;; Other required Elisp libraries
  30. ;;; ************************************************************************
  31.  
  32. (require 'br-lib)
  33.  
  34. ;;; ************************************************************************
  35. ;;; User visible variables
  36. ;;; ************************************************************************
  37.  
  38. (defvar clos-lib-search-dirs nil
  39.   "List of directories below which CLOS Library source files are found.
  40. Subdirectories of Library source are also searched.  A Library is a stable
  41. group of classes.")
  42.  
  43. (defvar clos-sys-search-dirs nil
  44.   "List of directories below which CLOS System source files are found.
  45. Subdirectories of System source are also searched.  A System class is one
  46. that is not yet reusable and is likely to change before release.")
  47.  
  48. (defconst clos-narrow-view-to-class nil
  49.  "*Non-nil means narrow buffer to just the matching class definition when displayed.")
  50.  
  51. ;;; ************************************************************************
  52. ;;; Internal functions
  53. ;;; ************************************************************************
  54.  
  55. (defun clos-get-classes-from-source (filename &optional skip-tags
  56.                      skip-tags-cleanup)
  57.   "Scans FILENAME and returns cons of class list with parents-class alist.
  58. Handles multiple inheritance.  Assumes file existence and readability have
  59. already been checked.
  60.    With optional SKIP-TAGS non-nil, does not compute and store lookup tags
  61. for element definitions.  If SKIP-TAGS is nil, normally a cleanup
  62. function is called after scanning the elements.  SKIP-TAGS-CLEANUP
  63. non-nil suppresses this action."
  64.   (let ((no-kill (get-file-buffer filename))
  65.     classes class parents parent-cons parent-list signatures)
  66.     (if no-kill
  67.     (set-buffer no-kill)
  68.       (funcall br-view-file-function filename))
  69.     (save-excursion
  70.       (save-restriction
  71.     (widen)
  72.     (goto-char (point-min))
  73.     (if skip-tags
  74.         nil
  75.       (setq signatures (clos-scan-features))
  76.       (goto-char (point-min)))
  77.     (while (re-search-forward clos-class-def-regexp nil t)
  78.       (setq class (buffer-substring (match-beginning 1) (match-end 1))
  79.         parent-list nil)
  80.       (while (looking-at clos-parent-regexp)
  81.         (setq parent-list
  82.           (cons (buffer-substring
  83.              (match-beginning 1)
  84.              (match-end 1))
  85.             parent-list))
  86.         (goto-char (match-end 0)))
  87.       (setq parent-list (nreverse parent-list))
  88.       (if (and (null parent-list)
  89.            (not (equal class "t")))
  90.           ;; All classes have t as an ancestor, so if
  91.           ;; no parents are listed, make t the sole parent.
  92.           (setq parent-list '("t")))
  93.       (setq parent-cons (cons parent-list class))
  94.       ;; Don't have to check whether class-def pattern begins
  95.       ;; after a comment since the regexp used for matching
  96.       ;; precludes this.
  97.       (setq classes (cons class classes)
  98.         parents (cons parent-cons parents)))))
  99.     (if skip-tags
  100.     nil
  101.       (clos-get-feature-tags
  102.        buffer-file-name (clos-sort-features signatures))
  103.       (or skip-tags-cleanup (br-feature-tags-save)))
  104.     (or no-kill (kill-buffer (current-buffer)))
  105.     (cons classes (delq nil parents))))
  106.  
  107. (defun clos-get-parents-from-source (filename class-name)
  108.   "Scan source in FILENAME and return list of parents of CLASS-NAME.
  109. Assume file existence has already been checked."
  110.     (cond ((null class-name) nil)
  111.       ((equal filename br-null-path)
  112.        ;; This means there is no source for this class, so 
  113.        ;; since all classes have t as an ancestor and there is no where
  114.        ;; to look for parents, make t the sole parent.
  115.        '("t"))
  116.       (t (let ((br-view-file-function 'br-insert-file-contents))
  117.            (car (car (br-rassoc
  118.               class-name
  119.               (cdr (clos-get-classes-from-source
  120.                 filename t)))))))))
  121.  
  122. (defun clos-select-path (paths-htable-elt &optional feature-p)
  123.   "Select proper pathname from PATHS-HTABLE-ELT based upon value of optional FEATURE-P.
  124. Selection is between path of class definition and path for features associated
  125. with the class."
  126.   (let ((elt (cdr paths-htable-elt)))
  127.     (if (consp elt) 
  128.     (if feature-p (cdr elt) (car elt))
  129.       ;; Both paths are the same.
  130.       elt)))
  131.  
  132. (defun clos-set-case (type)
  133.   "Return string TYPE identifier for use as a class name."
  134.   type)
  135.  
  136. (defun clos-set-case-type (class-name)
  137.   "Return string CLASS-NAME for use as a type identifier."
  138.   class-name)
  139.  
  140. (defun clos-to-class-end ()
  141.   "Assuming point is at start of class, move to start of line after end of class."
  142.   (interactive)
  143.   (goto-char (point-max))
  144.   )
  145.  
  146. (defun clos-to-comments-begin ()
  147.   "Skip back from current point past any preceding CLOS comments."
  148.   (let ((opoint))
  149.     (while
  150.     (progn (setq opoint (point))
  151.            ;; To previous line
  152.            (if (= 0 (forward-line -1))
  153.            (cond
  154.              ;; If begins with ";", then is a comment.
  155.              ((looking-at "[ \t]*\\(;\\|$\\)"))
  156.              (nil)))))
  157.     (goto-char opoint)
  158.     ;; Skip past whitespace
  159.     (skip-chars-forward " \t\n")
  160.     (beginning-of-line)))
  161.  
  162. ;;; ************************************************************************
  163. ;;; Internal variables
  164. ;;; ************************************************************************
  165.  
  166. (defconst clos-class-keyword
  167.   "(defclass[ \t]+"
  168.   "Keyword regexp preceding a clos class definition.")
  169.  
  170. (defconst clos-class-name-before
  171.   (concat "^[ \t]*" clos-class-keyword)
  172.   "Regexp preceding the class name in a class definition.")
  173.  
  174. (defconst clos-class-name-after
  175.   "[ \t\n]*\("
  176.   "Regexp following the class name in a class definition.")
  177.  
  178.  
  179. (defconst clos-identifier-chars      "a-zA-Z0-9+*/_~!@$%^&=:<>{}|.-"
  180.   "String of chars and char ranges that may be used within a CLOS identifier.")
  181.  
  182. (defconst clos-type-identifier-chars "][a-zA-Z0-9+*/_~!@$%^&=<>{}|.-"
  183.   "String of chars and char ranges that may be used within a CLOS class name.
  184. No colons allowed.")
  185.  
  186. (defconst clos-identifier (concat "\\([" clos-identifier-chars "]+\\)")
  187.   "Regular expression matching a CLOS identifier.")
  188.  
  189. (defconst clos-class-def-regexp
  190.   (concat clos-class-name-before clos-identifier clos-class-name-after)
  191.   "Regular expression used to match to class definitions in source text.
  192. Class name identifier is grouped expression 1.  Parent class names
  193. follow this expression, which terminates with the parenthesis that begins
  194. the parent class group.")
  195.  
  196. (defconst clos-lang-prefix "clos-"
  197.  "Prefix string that starts \"br-clos.el\" symbol names.")
  198.  
  199. (defconst clos-parent-regexp
  200.   (concat "[ \t\n]*" clos-identifier)
  201.   "Parent identifier is grouped expression 1.")
  202.  
  203. (defconst clos-file-dir-regexp "^[^.~#].*[^.~#]$"
  204.   "Regexp that ignores extraneous non-source files and directories.")
  205.  
  206. (defconst clos-src-file-regexp ".\\.\\(lisp\\|lsp\\|cl\\|el\\)$"
  207.   "Regular expression matching a unique part of CLOS source file names and no others.")
  208.  
  209. (defvar clos-children-htable nil
  210.   "Htable whose elements are of the form: (LIST-OF-CHILD-CLASSES . CLASS-NAME).
  211. Used to traverse CLOS inheritance graph.  'br-build-children-htable' builds
  212. this list.")
  213. (defvar clos-parents-htable nil
  214.   "Htable whose elements are of the form: (LIST-OF-PARENT-CLASSES . CLASS-NAME).
  215. Used to traverse CLOS inheritance graph.  'br-build-parents-htable' builds
  216. this list.")
  217. (defvar clos-paths-htable nil
  218.   "Htable whose elements are of the form: (LIST-OF-CLASS-NAMES . FILE-PATH).
  219. FILE-PATH gives the location of classes found in LIST-OF-CLASS-NAMES.
  220. 'br-build-paths-htable' builds this list.")
  221.  
  222.  
  223. (defvar clos-lib-parents-htable nil
  224.   "Htable whose elements are of the form: (LIST-OF-PARENT-CLASSES . CLASS-NAME).
  225. Only classes from stable software libraries are used to build the list.")
  226. (defvar clos-lib-paths-htable nil
  227.   "Htable whose elements are of the form: (LIST-OF-CLASS-NAMES . FILE-PATH).
  228. FILE-PATH gives the location of classes found in LIST-OF-CLASS-NAMES.
  229. Only classes from stable software libraries are used to build the list.")
  230.  
  231. (defvar clos-sys-parents-htable nil
  232.   "Htable whose elements are of the form: (LIST-OF-PARENT-CLASSES . CLASS-NAME).
  233. Only classes from systems that are likely to change are used to build the list.")
  234. (defvar clos-sys-paths-htable nil
  235.   "Alist whose elements are of the form: (LIST-OF-CLASS-NAMES . FILE-PATH).
  236. FILE-PATH gives the location of classes found in LIST-OF-CLASS-NAMES.
  237. Only classes from systems that are likely to change are used to build the
  238. list.")
  239.  
  240. (defvar clos-lib-prev-search-dirs nil
  241.   "Used to check if 'clos-lib-classes-htable' must be regenerated.")
  242. (defvar clos-sys-prev-search-dirs nil
  243.   "Used to check if 'clos-sys-classes-htable' must be regenerated.")
  244.  
  245. (defvar clos-env-spec nil
  246.   "Non-nil value means Environment specification has been given but not yet built.
  247. Nil means current Environment has been built, though it may still require updating.")
  248.  
  249. (provide 'br-clos)
  250.